package com.wk.data4glib;

import android.app.Activity;

/**
 *  控制命令socket链接
 */
public class ControlCmdTcpTool {

    private WkTcpTool tcpTool;

    public void initAirContent(Activity activity , final WkSocketCallBack wkSocketCallBack , final int index ) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                String serverIp= ServerConfig.getServerIp(false);
                int serPort =ServerConfig.getServerPort(1) ;
                tcpTool =  new WkTcpTool( serverIp,serPort  , wkSocketCallBack ,index) ;
            }
        }).start();
    }


    public void reConnectTcp(){
        if(tcpTool !=null){
            tcpTool.reConnectTcp();
        }
    }

    /**
     * 可以在主线程中调用
     */
    public void closeTcpConnection(){
        if(tcpTool !=null){
            tcpTool.closeAllConnection();
        }
    }


    /**
     * 发送数据线程., 可以在主线程、子线程中调用
     */
    public void sendData2Server(  byte[] bytes) {
        if(tcpTool!=null){
            tcpTool.sendDataBytes(bytes);
        }
    }

}
